<template>
  <div class="zgz">
    <!-- 头部 -->
  <head-usual :title="title" :to="to"></head-usual>
  <!-- 排序筛选-->
  <div class="fix-classify">
     <div class="body-all">
    <!-- 类型分类 -->
      <div class="body">
          <div class="area nav" @click="switchFilter('type')">
            <span>筑功者类型</span>
            <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-shang-copy-copy"></use>
            </svg>
          </div>
          <mt-popup class="tlm-popup tlm-popup-1" v-model="showType" position="top" popup-transition="popup-fade">
            <ul class="body-tanchu">
                <li class="area-li">
                    <a @click="handleFilter('status',0)" v-bind:class="{ active: 0==searchCondition.type }">不限</a>
                </li>
                <li v-for="(item,index) in this.$store.state.filter_ZgzType" :key="index" >
                    <a @click="handleFilter('type',item.id)" v-bind:class="{ active: item.id==searchCondition.type }">{{item.name}}</a>
                </li>
            </ul>
          </mt-popup>
          <div class="major nav" @click="switchFilter('industrycla')">
            <span>行业类型</span>
            <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-shang-copy-copy"></use>
            </svg>
          </div>
          <mt-popup class="tlm-popup tlm-popup-2" v-model="showIndustrycla" position="top" popup-transition="popup-fade">
              <ul class="body-tanchu">
                  <li class="area-li" >
                      <a @click="handleFilter('industrycla','all')" v-bind:class="{ active: 'all'==searchCondition.industrycla }">不限</a>
                  </li>
                  <li v-for="(item,index) in this.$store.state.filter_Hyfl" :key="index" >
                      <a @click="handleFilter('industrycla',item.name)" v-bind:class="{ active: item.name==searchCondition.industrycla }">{{item.name}}</a>
                  </li>
              </ul>
          </mt-popup>
          <div class="major-classify nav" @click="switchFilter('role')">
            <span>行业角色</span>
            <svg class="icon" aria-hidden="true">
                <use xlink:href="#icon-shang-copy-copy"></use>
            </svg>
          </div>
          <mt-popup class="tlm-popup tlm-popup-3" v-model="showRole" position="top" popup-transition="popup-fade" >
              <ul class="body-tanchu">
                <li class="area-li" >
                      <a @click="handleFilter('role','all')" v-bind:class="{ active: 'all'==searchCondition.role }">不限</a>
                  </li>
                  <li v-for="(item,index) in this.$store.state.filter_Role" :key="index" >
                      <a @click="handleFilter('role',item.name)" v-bind:class="{ active: item.name==searchCondition.role }">{{item.name}}</a>
                  </li>
              </ul>
          </mt-popup>
      </div>
    </div>
    <div class="classify">
       <div v-bind:class="(searchCondition.sort.indexOf('all') != -1?'active ':'')+' classify-item'" @click="handleRank('all')">综合  {{searchCondition.sort=="all"?'↓':'↑'}}</div>
      <div v-bind:class="(searchCondition.sort.indexOf('r') != -1?'active ':'')+' classify-item'" @click="handleRank('r')">热门  {{searchCondition.sort=="r1"?'↓':'↑'}}</div>
      <div v-bind:class="(searchCondition.sort.indexOf('c') != -1?'active ':'')+' classify-item'" @click="handleRank('c')">成交量 {{searchCondition.sort=="c1"?'↓':'↑'}}</div>
      <div v-bind:class="(searchCondition.sort.indexOf('h') != -1?'active ':'')+' classify-item'" @click="handleRank('h')">好评率 {{searchCondition.sort=="h1"?'↓':'↑'}}</div>
    </div>
  </div>
   
  <div class="companyList" v-infinite-scroll="loadMore" infinite-scroll-disabled="loading" infinite-scroll-distance="20">
    <router-link class="company-list-item" v-bind:to="item.url+item.id" v-for="(item,index) in pagedListData" :key="index">
        <dl>
            <dt class="company-dt">
                <img :src="item.headportrait" class="company-dt-img company-img"/>
            </dt>
            <dd class="company-dd">
                <p class="company-dd-p1">
                  <span v-bind:class="item.grade>0?'nameStyle':''">{{item.name}}</span>
                  <span class="company-p1-right" v-if="item.type==2">企业</span>
                  <span class="company-p1-right company-dd-person" v-else>个人</span>
                </p>
                <p class="company-dd-p2">
                    <span v-for="(item,index) in item.Arr_tags" :key="index">{{item}}</span>
                </p>
                <p class="company-dd-p3">
                    <span>浏览量</span>
                    <span>{{item.hits}}</span>
                    <span class="p3-fenge"></span>
                    <span class="fenge-right">好评率</span>
                    <span>{{item.praiseRate}}%</span>
              </p>
              <p class="company-dd-p4">
                  <span class="company-p4-left">服务</span>
                  <span class="company-p4-right">{{item.introduction}}</span>
              </p>
            </dd>
        </dl>
    </router-link>
    <div v-show="loading" class="page-infinite-loading">
      <mt-spinner type="fading-circle"></mt-spinner>
      加载中...
    </div>
    <div v-show="allLoaded" class="page-infinite-data">亲！别拉了我是有底线的</div>
  </div>  
  <!-- 底部 -->
  <footerTotal></footerTotal>
  </div>
</template>

<script>
import { GetPageList } from "@/api/zgz"; 

export default {
  data() {
    return {
      title: "筑功者",
      to:'/',
      pagedListData:[],
      showType:false,
      showIndustrycla:false,
      showRole: false,
      searchCondition: {
        type: 0,//筑功者类型
        industrycla:'all',//行业分类
        role:'all',//角色
        pageindex: 1,//页码
        sort:'r1',//排序
        area:''
      },
      loading: false, //是否显示加载中
      allLoaded: false, //加载完毕
      totalpage: 1, //总页码
    };
  },
  created() {
    this._getPagedList();
  },
  methods: {
    //操作排序
    handleRank(cmd) {
      if (this.searchCondition.sort.indexOf("1") != -1) {
        this.searchCondition.sort = cmd + "2";
      } else {
        this.searchCondition.sort = cmd + "1";
      }
      this._getPagedList();
    },
    switchFilter(type){
        //顶部切换 筛选条件
      switch (type) {
        case "type":
          {
            this.showType = true;
            this.showIndustrycla = false;
            this.showRole = false;
          }
          break;
        case "industrycla":
          {
            this.showType = false;
            this.showIndustrycla = true;
            this.showRole = false;
          }
          break;
        case "role":
          {
            this.showType = false;
            this.showIndustrycla = false;
            this.showRole = true;
          }
          break;
        default:
          break;
      }
    },
    handleFilter(type, value){
        switch (type) {
        case "type":
          {
           this.searchCondition.type=value;
          }
          break;
        case "industrycla":
          {
             this.searchCondition.industrycla=value;
          }
          break;
        case "role":
          {
             this.searchCondition.role=value;
          }
          break;
        default:
          break;
      }

      this.showType = false;
      this.showIndustrycla = false;
      this.showRole = false;
      this._getPagedList();
    },
    loadMore() {
      //分页加载更多
        console.log("分页"+ this.searchCondition.pageindex+"xxxx"+this.totalpage)
      
      if (this.searchCondition.pageindex >= this.totalpage) {
        this.allLoaded = true;
        return;
      }
      this.loading = true;
      setTimeout(() => {
        this.searchCondition.pageindex++;
        GetPageList(this.searchCondition).then(res => {
          if (res.StatusCode === 200) {
            this.pagedListData = this.pagedListData.concat(res.Data);
          }
        });
        this.loading = false;
      }, 1000);
    },
    // 获取数据
    _getPagedList() {
      this.$indicator.open();
      GetPageList(
        this.searchCondition
      ).then(res => {
        if (res.StatusCode === 200) {
          this.pagedListData = res.Data;
        
          this.totalpage = res.TotalPage;
          console.log("获取数据"+this.totalpage);
          this.$indicator.close();
        }
      });
    }
  },
};
</script>

<style scoped lang='scss'>

.fix-classify{
  position: fixed;
  left: 0;
  right:0;
  top:52px;
  background: #fff;
  display: block;
  z-index: 999;
 
}
.body-all {
  position: relative;
  background: #fff;
}
/* 分类*/
.body {
  width: 100%;
  height: 44px;
  display: flex;
  border-top: 1px solid #f4f4f4;
  text-align: center;
  background: #fff;
  //分类下每一个选项
  .nav {
    width: 33.3%;
    border-right: 1px solid #f4f4f4;
    // border-bottom: 1px solid #ccc;
    line-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    span {
      font-size: 14px;
      color: #333333;
    }
    .icon{
      font-size: 18px;
    }
    .icon-active {
      color: #fd4f00;
    }
  }
  // 角色分类右边框消失
  .major-classify {
    border-right: none !important;
  }
}
.body-tanchu {
  width: 100%;
  background: white;
  padding: 15px 12px 2px 12px;
  display: flex;
  flex-wrap: wrap;
}
.body-tanchu > li {
  display: flex;
  text-align: center;
  flex:0 0 33.3%;
  margin-bottom: 10px;
  justify-content: center;

  
    a{
       width: 115px;
      height: 34px;
      overflow: hidden;
  text-overflow:ellipsis;
  white-space: nowrap;
      line-height: 34px;
      border: 1px solid #eeeeee;

    }
  
}
.popup-layer {
  width: 414px;
  background-color: #fff;
  padding: 0;
  margin: 0;
  left: 50%;
  position: absolute;
}
// 弹出阴影层
.body-all > .v-modal {
  width: 100%;
  height: 73%;
}
.hidden {
  width: 100%;
  z-index: 99999;
  height: 88px;
  position: absolute;
  top: -44px;
  left: 0;
  background-color: white;
  opacity: 0;
}
.active {
  border-color: #fd4f00 !important;
  color: #fd4f00 !important;
}
/* 3个排序 */
.classify {
  width: 100%;
  height: 42px;
  background: #f9f9f9;
  display: flex;
  align-items: center;
  text-align: center;
  border-bottom: 1px solid #eeeeee;
  background: #fff;
  .classify-item {
    width: 33.3%;
    font-size: 14px;
    color: #282828;
  }
  .active {
    color: #fd4f00 !important;
  }
}
// 公司列表

.companyList {
  position: relative;
  margin-top: 85px;
  .company-list-item {
    width: 100%;
    display: block;
    padding-bottom: 16.3px;
    border-bottom: 10px solid rgb(238, 238, 238);
    dl {
      overflow: hidden;
      .company-dt {
        width: 74.6px;
        height: 74.6px;
        overflow: hidden;
        float: left;
        margin-top: 16.3px;
        margin-left: 12px;
        /* 保持图片不失真 */
        .company-img {
          width: 100%;
          max-width: 100%;
          height: auto;
          display: block;
          // margin-top: 20.65px;
          // margin-left: 5.15px;
        }
        .person-img {
           width: 100%;
            max-width: 100%;
            height: auto;
            display: block;
        }
      }
    }
    .company-dd {
      float: left;
      margin-left: 11.6px;
      margin-top: 16.3px;
      .company-dd-p1 {
        font-size: 18px;
        color: #333333;
        margin-bottom: 11.66px;
        overflow: hidden;
        display: flex;
        align-items: center;
        span {
          display: block;
          float: left;
        }
        .company-p1-right {
          display: inline-block;
          font-size: 12px;
          float: left;
          color: #ffffff;
          background: #fd4f00;
          padding: 0px 6px;
          margin-left: 7px;
          margin-top: 3px;
        }
        .person-fenge {
          width: 0;
          height: 15px;
          border: 1px solid rgb(40, 40, 40);
          display: inline-block;
          margin-left: 13px;
          margin-right: 13px;
         
        }
        .company-dd-person {
          background: rgb(56, 135, 254) !important;
          margin-left: 7px;
        }
        .nameStyle{
          color: #ea544a
        }
      }
    }
    .company-dd-p2 {
      margin-bottom: 12px;
      height: 28.666px;
      span {
        display: block;
        float: left;
        color: #fd4f00;
        font-size: 14px;
        margin-right: 10px;
        padding: 2px 3px;
        border: 1px solid #fd4f00;
      }
      .company-p2-last {
        margin-right: 0px !important;
      }
    }
    .company-dd-p3 {
      font-size: 12px;
      color: #999999;
      height: 11.3px;
      margin-bottom: 13px;
      display: flex;
      align-items: center;
      span {
        float: left;
        color: #666666;
        display: block;
        margin-right: 4px;
        line-height: 9.81px;
        font-size: 12px;
      }
      .p3-fenge {
        display: block;
        float: left;
        width: 0px;
        height: 8px;
        border: 1px solid #999999;
        margin-left: 10px !important;
        margin-right: 15px !important;
      }
    }
    .company-dd-p4 {
      overflow: hidden;
      margin-bottom: 14px;
      .company-p4-left {
        display: block;
        float: left;
        font-size: 12px;
        color: #fff;
        padding: 0px 6px;
        background: rgb(255, 186, 0);
      }
      .company-p4-right {
        display: block;
        float: left;
        font-size: 12px;
        color: rgb(102, 102, 102);
        margin-left: 6.66px;
        line-height: 18px;
        width: 240px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        margin-top:2px;
      }
    }
  }
}
</style>
